<?php
	// 方法: echo的中文不会乱码
	header('Content-Type:text/plain;charset=utf-8');
	//127.0.0.1
	//172.31.3.21
	$pdo =new pdo("mysql:host=172.31.3.21;port=3306;dbname=tddb;","root","tdled2018");//PDO连接MySQL
	$pdo->query("set character set 'utf8'");//读库
	$pdo->query("set names 'utf8'");//写库
	//姓名的语句
	$sql = "
	SELECT
		 GongXu AS 工序
		,h.KaoXiangHao AS 烤箱号
		,KXMen AS 烤箱门
		,GongDanHao AS 工单号
		,PCS AS '数量(片)'
		,InGongHao AS 进烤人工号
		,p1.Name AS 进烤人姓名
		,InTime AS 进烤时间
		,OutGongHao AS 出烤人工号
		,p2.Name AS 出烤人姓名
		,OutTime AS 出烤时间
	FROM
		kaoxiang_h AS h
	INNER JOIN
		kaoxiang_d AS d
	ON
		h.KXHID = d.KXHID
	LEFT JOIN
		person AS p1
	ON
		InGongHao = p1.QR
	LEFT JOIN
		person AS p2
	ON
		OutGongHao = p2.QR
	LEFT JOIN
		kaoxiang_tab AS t
	ON
		t.KaoXiangHao = h.KaoXiangHao
	WHERE
		DATE(InTime) >= CURDATE()-3
	";
	$res=$pdo->prepare($sql);//准备查询语句
	$res->execute(); //执行一条查询语句
	$KX=$res->fetchAll();//取出所有行
	echo json_encode(array('KX'=>$KX));//转码成json
?>